
Partial Class SProcD
    Inherits System.Web.UI.Page

    Private Const Q As String = Chr(34)

    Private moServer As SQLAutoDocLib.Server = Nothing
    Private moDatabase As SQLAutoDocLib.Database = Nothing
    Private moOwner As SQLAutoDocLib.Login = Nothing
    Private moProc As SQLAutoDocLib.SProc = Nothing

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim sSID As String
        Dim sDID As String
        Dim sOID As String
        Dim sREV As String = ""
        Dim sIsFramed As String = ""

        If IsPostBack = False Then
            sSID = Request.QueryString("S")
            sDID = Request.QueryString("D")
            sOID = Request.QueryString("O")
            sREV = Request.QueryString("R")
            sIsFramed = Request.QueryString("F")

            hidSID.Value = sSID
            hidDID.Value = sDID
            hidOID.Value = sOID
            hidRID.Value = sREV
        Else
            hidRID.Value = Request.Form("cmbRev")
            sREV = Request.Form("cmbRev")

            sSID = hidSID.Value
            sDID = hidDID.Value
            sOID = hidOID.Value
            sREV = cmbRev.Value
        End If

        moServer = New SQLAutoDocLib.Server(sSID)
        moServer.Load()

        moDatabase = New SQLAutoDocLib.Database(sDID)
        moDatabase.Load()

        If Not IsNumeric(sREV) Then
            moProc = New SQLAutoDocLib.SProc(sOID)
        Else
            moProc = New SQLAutoDocLib.SProc(sOID, sREV)
        End If
        moProc.Load()

        moOwner = New SQLAutoDocLib.Login(moProc.OwnerID)
        moOwner.Load()

        If IsPostBack = False Then
            If Not IsNumeric(sIsFramed) Then
                Dim oRevFactory As New SQLAutoDocLib.SProc_Factory
                Dim oList As ArrayList = oRevFactory.GetAllSProcRevs(moProc.ID)
                For Each oRev As SQLAutoDocLib.SProc In oList
                    cmbRev.Items.Add(New ListItem(oRev.RevDate, oRev.RevID))
                Next

                hidRID.Value = oList.Item(0).RevID
                txtDesc.Value = moProc.Desc

            Else
                cmbRev.Visible = False
                lblRev.Visible = True

                lblRev.InnerText = moProc.CreateDate
                txtDesc.Visible = False

                If moProc.Desc > "" Then
                    lblDesc.Style.Add("border", "solid 1px grey")

                    lblDesc.InnerHtml = "<pre>" & moProc.Desc & "</pre>"
                Else
                    lblDesc.Style.Add("height", "1px")
                End If
            End If

        ElseIf hidToolbarAction.Value = "refresh" Then
            txtDesc.Value = moProc.Desc

        ElseIf hidToolbarAction.Value = "save" Then
            moProc.Desc = txtDesc.Value
            moProc.Save()

            Dim oExtendedProperties As New SQLAutoDocLib.ExtendedProperties
            oExtendedProperties.UpdateSProcDescription(moProc.DatabaseID, moProc.ID, txtDesc.Value)

        ElseIf hidToolbarAction.Value = "back" Then
            Server.Transfer("SQSProcE.aspx?S=" + hidSID.Value & "&D=" & hidDID.Value)
        End If
    End Sub

    Protected Sub ShowSProcDetail()
        Dim lsProcID As Long = hidOID.Value
        Dim lRevID As Long = hidRID.Value

        Dim oViewReporter As New SQLAutoDocLib.Rpt_SProcs
        oViewReporter.ShowSProcDetail(lsProcID, lRevID)
    End Sub

    Protected Function FormLabel() As String
        Return "Procedure: " & moOwner.Login & "." & moProc.Name
    End Function

    Protected Function ScanMode() As String
        Return "SProcs"
    End Function

    Protected Function EditMode() As String
        Return "SProc"
    End Function

    Protected Function ServerID() As String
        Return moServer.ID
    End Function

    Protected Function DatabaseID() As String
        Return moDatabase.ID
    End Function

    Protected Function ObjectID() As String
        Return moProc.ID
    End Function

    Protected Function ObjectRev() As String
        Return moProc.RevID
    End Function
End Class
